package cn.com.pdfdemo.controller;


import cn.com.pdfdemo.entity.ChildInfo;
import cn.com.pdfdemo.entity.Demo;
import cn.com.pdfdemo.entity.DemoSub;
import cn.com.pdfdemo.pdfUtil.PdfUtil;
import cn.com.pdfdemo.pdfUtil.entity.MyPdfEntity;
import com.itextpdf.layout.property.TextAlignment;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.List;

/**
 * 导出测试
 *
 * @author ruoyi
 */
@Controller
@RequestMapping("/itext/export")
public class ItextController {

    // 1、pdf下载 （纯表单）
    @GetMapping("/download1")
    public void download1(HttpServletResponse response) throws Exception {
        Demo Demo = new Demo();
        Demo.setTitle("我是大标题！！！！");
        Demo.setId(11111L);
        Demo.setMobile("15151515151");
        Demo.setTime("2024-07-24");
        Demo.setPrice(199.99);
        Demo.setRamark("恩菲话说开了翻看了你放开啦立法卡夫卡爱克发,你看发来看啊离开诺福克拉风了容量你那看来发哪里看我,发男篮违反来看我呢安莉芳看看留尼汪,卡拉翻看了王飞龙安费诺卡拉问我能否考虑安弗里克亲王过来我弄个群,去哪玩覅穷鬼琴女那请问能,否你哦去,年覅哦亲你无法");
        // 表单设置
        MyPdfEntity myPdfEntity = new MyPdfEntity<>();
        // 每列的宽度
        myPdfEntity.setTableWidth(new float[]{100,200,100,200});
        myPdfEntity.setTitle("测试大标题");
        myPdfEntity.setTextAlignment(TextAlignment.CENTER);
        PdfUtil.down(Demo, myPdfEntity, response);
    }

    // 2、pdf下载 （表单 + 表格）
    @GetMapping("/download2")
    public void download2(HttpServletResponse response) throws Exception {
        Demo demo = new Demo();
        demo.setTitle("我是大标题！！！！");
        demo.setId(11111L);
        demo.setMobile("15151515151");
        demo.setTime("2024-07-24");
        demo.setPrice(199.99);
        demo.setRamark("恩菲话说开了翻看了你放开啦立法卡夫卡爱克发,你看发来看啊离开诺福克拉风了容量你那看来发哪里看我,发男篮违反来看我呢安莉芳看看留尼汪,卡拉翻看了王飞龙安费诺卡拉问我能否考虑安弗里克亲王过来我弄个群,去哪玩覅穷鬼琴女那请问能,否你哦去,年覅哦亲你无法");

        DemoSub demoSub = new DemoSub();
        demoSub.setItemNo("123123");
        demoSub.setItemType("商品类型111");
        demoSub.setItemName("商品名称aaa");
        demoSub.setMsg("备注备注备注");
        List<DemoSub> demoSubList = new ArrayList<>();
        demoSubList.add(demoSub);

        // 此处只是为了表示能放多个不用的表格
        demo.setDemoSubs1(demoSubList);
        demo.setDemoSubs2(demoSubList);

        // 表单设置
        MyPdfEntity myPdfEntity = new MyPdfEntity<>();
        // 每列的宽度
        myPdfEntity.setTableWidth(new float[]{100,200,100,200});
        myPdfEntity.setTitle("测试大标题");
        myPdfEntity.setTextAlignment(TextAlignment.CENTER);
        PdfUtil.down(demo, myPdfEntity, response);
    }

    // 3、pdf下载 多（表单 + 表格）
    @GetMapping("/download3")
    public void download3(HttpServletResponse response) throws Exception {
        List<Demo> demoList = new ArrayList<>();
        for (int k = 0; k < 3; k++) {
            Demo demo = new Demo();
            demo.setTitle("我是表格标题！！！！");
            demo.setId(11111L);
            demo.setMobile("15151515151");
            demo.setTime("2024-07-24");
            demo.setPrice(199.99);
            demo.setRamark("恩菲话说开了翻看了你放开啦立法卡夫卡爱克发,你看发来看啊离开诺福克拉风了容量你那看来发哪里看我,发男篮违反来看我呢安莉芳看看留尼汪,卡拉翻看了王飞龙安费诺卡拉问我能否考虑安弗里克亲王过来我弄个群,去哪玩覅穷鬼琴女那请问能,否你哦去,年覅哦亲你无法");

            List<DemoSub> demoSubList = new ArrayList<>();
            for (int i = 0; i < 5; i++) {
                DemoSub demoSub = new DemoSub();
                demoSub.setItemNo("123123");
                demoSub.setItemType("商品类型111");
                demoSub.setItemName("商品名称aaa");
                demoSub.setMsg("备注备注备注");
                demoSubList.add(demoSub);
            }
            // 此处为了表示 每种表格的多列
            demo.setDemoSubs1(demoSubList);
            demoList.add(demo);
        }

        // 表单设置
        MyPdfEntity myPdfEntity = new MyPdfEntity<>();
        // 每列的宽度
        myPdfEntity.setTableWidth(new float[]{100,200,100,200});
        myPdfEntity.setTitle("测试大标题");
        myPdfEntity.setTextAlignment(TextAlignment.CENTER);
        PdfUtil.down(demoList, myPdfEntity, response);
    }
}


